import sys

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QFrame, QVBoxLayout, QHBoxLayout, \
    QCheckBox, QSlider, QProgressBar, QMainWindow, QAction, QMessageBox

'''
菜单 多级菜单配置 QMainWindow
利用菜单界面跳转新窗口或提示
Qmenu菜单类实现多级菜单addAtion直接产生点击事件行为，addMenu增加子菜单
        actHelp = QAction('帮助', self)
        actHelp.triggered.connect(self.myHelp)  # 触发
        mymenu.addAction(actHelp)
        
新窗体 重新定义一个类 MyWindow()
'''


class MyClass(QMainWindow):  # 继承 QMainWindow
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程')
        self.setGeometry(800, 370, 400, 300)

        mymenu = self.menuBar()

        fmenu = mymenu.addMenu('文件')
        newWin = QAction('新建窗体', self)
        newWin.triggered.connect(self.myNewWin)
        fmenu.addAction(newWin)
        recentFile = fmenu.addMenu('最新...')
        recentFile.addAction('文件1')
        recentFile.addAction('文件2')
        recentFile.addAction('文件3')

        mymenu.addMenu('运行')
        mymenu.addMenu('调试')

        actHelp = QAction('帮助', self)
        actHelp.triggered.connect(self.myHelp)
        mymenu.addAction(actHelp)

        self.show()

    def myHelp(self):
        msgbox = QMessageBox(QMessageBox.Information, '帮助', '欢迎使用本系统', QMessageBox.Ok, self)
        msgbox.setWindowIcon(QIcon('./img/msn.ico'))
        msgbox.show()

    def myNewWin(self):
        list1.append(MyWindow())
        # myw.show()


class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('子窗口'+str(1+len(list1)))
        self.setGeometry(300+len(list1)*20, 270+len(list1)*20, 300, 200)

        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myf = MyClass()
    list1 = []  # 多窗体实现
    app.exec_()
